/*
 * $Id: TcpSocket.m,v 1.2 2005-11-20 14:34:28 bacon Exp $
 */

#include <xpo/net/TcpSocket.h>

@implementation XpTcpSocket

+ (XpTcpSocket*) open: (int) mode
{
	XpTcpSocket* p = [self alloc];
	if (p == nil) return nil;

	[super init];
	if (xp_tcp_open (&p->handle, mode) == XP_NULL) {
		[p dealloc];
		return nil;
	}

	return p;
}

- (int) close
{
	if (xp_tcp_close (&self->handle) == -1) return -1;
	[self dealloc];
	return 0;
}

- (int) connect: (TcpAdddress*) addr;
{
	return xp_tcp_connect (&self->handle, [addr port], [addr host], 0);
}

#if 0
- (int) bind: (TcpAddress*) addr;
{
}
#endif

- (xp_ssize_t) send: (const void*) data size: (xp_size_t) size
{
	return xp_tcp_send (&self->handle, data, size);
}

- (xp_ssize_t) receive: (void*) buf size: (xp_size_t) size
{
	return xp_tcp_receive (&self->handle, buf, size);
}

@end
